AddressTextField.inherit("Control");

function AddressTextField(node){
	this.Control(node);
	
	this.submitState=this.properties.getObject("submitState");
	
	//WTF!
	this.popupParameterPrefix="address";

	this.street1Form=document.getElementById(this.properties.getString("street1Id"));
	this.street2Form=document.getElementById(this.properties.getString("street2Id"));
	this.street3Form=document.getElementById(this.properties.getString("street3Id"));
	
	this.cityForm=document.getElementById(this.properties.getString("cityId"));
	this.stateForm=document.getElementById(this.properties.getString("stateId"));
	this.zipForm=document.getElementById(this.properties.getString("zipId"));
	this.eventHandler=new EventHandler(this, this.street1Form, this.street2Form, this.street3Form, this.cityForm, this.stateForm, this.zipForm);
}

AddressTextField.prototype.getEventHandler=function () {
	return this.eventHandler;
}

AddressTextField.prototype.toString=function () {
	var state="";
	state= String.safeConcat(state,trim(this.submitState["street1"]), ", ");
	state= String.safeConcat(state,trim(this.submitState["street2"]), ", ");
	state= String.safeConcat(state,trim(this.submitState["street3"]), ", ");
	state= String.safeConcat(state,trim(this.submitState["city"]), ", ");
	state= String.safeConcat(state,trim(this.submitState["state"]), ", ");
	state= String.safeConcat(state,trim(this.submitState["zip"]), ", ");
	return state;
}

AddressTextField.prototype.populate=function(prefix, results){
	this.street1Form.value=results.getValue(prefix+".street1");
	this.street2Form.value=results.getValue(prefix+".street2");
	this.street3Form.value=results.getValue(prefix+".street3");		
	this.cityForm.value=results.getValue(prefix+".city");
	this.stateForm.value=results.getValue(prefix+".state");
	this.zipForm.value=results.getValue(prefix+".zip");
}

AddressTextField.prototype.populatePopupParameters=function (prefix, parameters) {
	parameters.add(prefix+".street1",this.street1Form.value);
	parameters.add(prefix+".street2",this.street2Form.value);
	parameters.add(prefix+".street3",this.street3Form.value);		
	parameters.add(prefix+".city",this.cityForm.value);
	parameters.add(prefix+".state",this.stateForm.value);
	parameters.add(prefix+".zip",this.zipForm.value);		
}

AddressTextField.prototype.clear=function () {
	this.street1Form.value="";
	this.street2Form.value="";
	this.street3Form.value="";
	this.cityForm.value="";
	this.stateForm.value="";
	this.zipForm.value="";
}
